// 如果没有通过拦截器配置域名的话，可以在这里写上完整的URL(加上域名部分)
// const origin = 'http://dogtan.club';
const origin = 'http://192.168.1.10:8212';

// 话
let wordListUrl = origin + '/frontend/word/get-word-list';
let wordDetailsUrl= origin + '/frontend/word/get-word-details';
// 图
let pictureListUrl = origin + '/frontend/picture/get-picture-list';
let pictureDetailsUrl= origin + '/frontend/picture/get-picture-details';
// 事
// 故事
// 我

// 共用
// 评论
let getCommentsUrl = origin + '/frontend/comment/get-comments';
let addCommentUrl = origin + '/frontend/comment/add-comment';

// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
  // 此处没有使用传入的params参数
	// let fetchWordList = (params = {}) => vm.$u.get(wordListUrl);
  // 此处使用了传入的params参数，一切自定义即可
  let fetchWordList = (params = {}) => vm.$u.get(wordListUrl, params);
  let fetchWordDetails = (params = {}) => vm.$u.get(wordDetailsUrl, params);
	// 图
	let fetchPictureList = (params = {}) => vm.$u.get(pictureListUrl, params);
	let fetchPictureDetails = (params = {}) => vm.$u.get(pictureDetailsUrl, params);

	// 评论
	let fetchGetComments = (params = {}) => vm.$u.get(getCommentsUrl, params);
	let fetchAddComment = (params = {}) => vm.$u.post(addCommentUrl, params);

  // 我的模块
  let fetchMineCourse = (params = {}) => {
    return vm.$u.get(mineCourseUrl + `/${params.uid}/${params.page}/${params.pageSize}`)
  };
  let fetchMineCertificate = (params = {}) => {
    return vm.$u.get(mineCertificateUrl + `/${params.uid}/${params.page}/${params.pageSize}`)
  };
  let fetchQuestions = (params = {}) => vm.$u.get(questionssUrl, params);
  let fetchAnswerResult = (params = {}) => vm.$u.get(answerResultUrl, params, {"content-type": "application/x-www-form-urlencoded"});

  // 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
  vm.$u.api = {
		fetchWordList,
		fetchWordDetails,
		fetchPictureList,
		fetchPictureDetails,
		// 评论
		fetchGetComments,
		fetchAddComment,
  };
}

export default {
  install
}
